package com.hottv.meeting.videomeeting.module.agora.view;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hottv.meeting.videomeeting.R;
import com.hottv.meeting.videomeeting.common.MeetingConfig;
import com.hottv.meeting.videomeeting.module.agora.data.MsgItem;
import com.hottv.meeting.videomeeting.module.meeting.MeetingManager;

import java.util.List;

/**
 * Created by chengwenqiang on 2019/6/4.
 */

public class MemAdapter extends BaseAdapter {

    private LayoutInflater mInflater;

    private List<String> mMemList;

    private Context mContext;
    public MemAdapter(Context context,List<String> memList) {
        super();

        this.mInflater = LayoutInflater.from(context);
        this.mMemList = memList;

    }

    public void setList(List<String> memList) {
        this.mMemList = memList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mMemList.size();
    }

    @Override
    public Object getItem(int position) {
        return mMemList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;

        if (convertView == null) {

            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.list_view_mem, null);
            holder.name = (TextView)convertView.findViewById(R.id.txt_name);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }

        String deviceId = mMemList.get(position);
        String name =  MeetingManager.getInstance().getNameFromDeviceId(deviceId);
        if(TextUtils.isEmpty(name))
        {
            name = deviceId;
        }
        Log.i(MeetingConfig.TAG,"MemAdapter name:"+name+",deviceId;"+deviceId);
        holder.name.setText(name);

        return convertView;
    }

    public final class ViewHolder{

        public TextView name;
    }
}
